package random.fox.p2p.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.RelativeLayout;
import android.widget.TextView;

import javax.inject.Inject;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import de.greenrobot.event.EventBus;
import flow.Flow;
import random.fox.p2p.App;
import random.fox.p2p.Paths;
import random.fox.p2p.R;
import random.fox.p2p.bean.BeanModule;
import random.fox.p2p.bean.greendao.User;
import random.fox.p2p.event.DrawLayoutEvent;
import random.fox.p2p.event.FinishActivityEvent;

/**
 * 菜单界面,就是左侧滑动界面
 * 这个界面偷懒，不应该这样写
 * Created by wq on 15/3/15.
 */
public class MenuView extends RelativeLayout {
    @Inject User user; //这样写打破了mvp
    @InjectView(R.id.tv_user_nickname)TextView nickname;
    public MenuView(Context context, AttributeSet attrs) {
        super(context, attrs);
        inflate(context, R.layout.menu_view, this);
        ((App)context.getApplicationContext()).createScopedGraph(new BeanModule()).inject(this);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        ButterKnife.inject(this);
        nickname.setText(user.getNickname());
    }

    @OnClick(R.id.imv_user_head) void goUserInfoActivity(){
        Flow.get(getContext()).set(new Paths.UserInfoPath());
//        Intent intent = new Intent(getContext() , UserInfoActivity.class);
//        getContext().startActivity(intent);
    }

    @OnClick(R.id.tv_hot) void hotClicked(){
        closeMenu();
        Flow.get(getContext()).set(new Paths.HotPath());
    }

    @OnClick(R.id.tv_like) void likeClicked(){
        closeMenu();
        Flow.get(getContext()).set(new Paths.LikePath());
    }

    @OnClick(R.id.tv_fans) void fansClicked(){
        closeMenu();
        Flow.get(getContext()).set(new Paths.FansPath());
    }

    @OnClick(R.id.tv_attention) void attentionClicked(){
        closeMenu();
        Flow.get(getContext()).set(new Paths.AttentionViewPath());
    }

    @OnClick(R.id.settings) void settingsOnClicked(){
        closeMenu();
        Flow.get(getContext()).set(new Paths.SettingPath());
    }

    @OnClick(R.id.exit) void exitOnClicked(){
        EventBus.getDefault().post(new FinishActivityEvent());
    }

    private void closeMenu(){
        EventBus.getDefault().post(new DrawLayoutEvent(true));
    }
}
